#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>

using namespace std;

static void vector_display(const vector<int>& v) {
    for (auto e : v)
        cout << e << ' ' ;
    cout << endl;
}

static bool prime(uint64_t n) {
    if (n < 2)
        return false;
    if (n == 2)
        return true;
    if (n % 2 == 0)
        return false;

    for (uint64_t i = 3; i * i <= n; i += 2) {
        if (n % i == 0)
            return false;
    }

    return true;
}

static bool arithmetic_progression(const vector<int>& v) {
    for (auto i = 0; i < v.size(); ++i) {
        for (auto j = i + 1; j < v.size(); ++j) {
            int t = v[i] + 2 * (v[j] - v[i]);
            if (find(v.begin(), v.end(), t) != v.end()) {
                cout << v[i] << v[j] << t << endl;
            }
        }
    }
    return false;
}

static void func0(int num) {
    vector<int> d;
    while (num) {
        d.push_back(num % 10);
        num /= 10;
    }
    sort(d.begin(), d.end());

    vector<int> v;
    do {
        int t = d[0] + 10 * d[1] + 100 * d[2] + 1000 * d[3];
        if (t > 1000 && prime(t))
            v.push_back(t);
    } while (next_permutation(d.begin(), d.end()));

    if (v.size() < 3)
        return;
    
    sort(v.begin(), v.end());
    arithmetic_progression(v);
}

int main() {
    for (int i = 1000; i < 10000; ++i)
        func0(i);
}